package com.shengwei.truck.driver.vm;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.shengwei.truck.driver.bean.Result;
import com.shengwei.truck.driver.bean.task.JsonOrderDetailData;
import com.shengwei.truck.driver.model.DataSource;
import com.shengwei.truck.driver.model.Repository;

/**
 * 登录页面的VM层，调用M层去获取数据，同时更改liveData的数据，从而View层就能观察到LiveData数据的
 * 变化，最后更新UI。
 */
public class OrderDetailViewModel extends ViewModel {
    String TAG = "OrderDetailViewModel";
    private Repository mRepository; //M层引用
    //订单详情
    private MutableLiveData<Result<JsonOrderDetailData>> mOrderDetailLiveData = new MutableLiveData<>();
    //申请任务
    private MutableLiveData<Result<String>> mApplayTaskLiveData = new MutableLiveData<>();

    /**
     * 构造函数
     * @param Repository: M层对象实例
     */
    public OrderDetailViewModel(Repository Repository) {
        this.mRepository = Repository;
    }
    public OrderDetailViewModel() {
        mRepository = Repository.getInstance(DataSource.getSingleInstance());
    }
    public MutableLiveData<Result<JsonOrderDetailData>> getOrderDetailLiveData() {
        return mOrderDetailLiveData;
    }

    public MutableLiveData<Result<String>> getApplayTask() {
        return mApplayTaskLiveData;
    }

    /**
     * 获得订单详情
     *
     * VM层调用M层（Repository+DataSource）
     * @param orderId : 订单ID
     * @return
     */
    public void getOrderDetail(String orderId) {
        mRepository.getOrderDetail(orderId,mOrderDetailLiveData);
    }


    /**
     * 申请任务
     * @param planOrderId：新订单ID（又称计划单ID）
     */
    public void applyTask(String planOrderId) {
        mRepository.applyTask(planOrderId,mApplayTaskLiveData);
    }
}